package com.guit.demo.client.jsonserializer;

import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.testing.MockSimpleBeanEditorDriver;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import com.google.inject.Inject;

import com.guit.demo.client.jsonserializer.JsonSerializerPresenter.CustomStyle;
import com.guit.demo.client.jsonserializer.JsonSerializerPresenter.JsonSerializerBinder;
import com.guit.demo.client.jsonserializer.JsonSerializerPresenter.PersonSerializer;
import com.guit.demo.client.main.MainPresenter;
import com.guit.junit.GuitTest;

import static junit.framework.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class TestJsonSerializerPresenter extends GuitTest {

  @Inject
  JsonSerializerPresenter presenter;

  @Override
  protected void configure() {
    mock(JsonSerializerBinder.class);
    mock(MainPresenter.class);
    mock(HasText.class);
    mock(HasValue.class);
    mock(CustomStyle.class);
    mock(HasStyleName.class);
    bind(PersonSerializer.class).toInstance(new PersonSerializer() {
      @Override
      public Person deserialize(String json) {
        return new Person();
      }

      @Override
      public String serialize(Person t) {
        return null;
      }
    });
  }

  @Override
  @Before
  public void setUp() {
    super.setUp();
    presenter.driver = new MockSimpleBeanEditorDriver<Person, Editor<Person>>();
    presenter.go(null);
  }

  @Test
  public void testJsonValueChange() {
    presenter.data = null;
    presenter.json.setText("");
    presenter.json$valueChange();
    assertNull(presenter.data);
  }
}
